package com.stu.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class PluginsDelayConfig {
    //延时交换机
    @Bean("orderDelayExchange")
    public CustomExchange newExchange(){
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-delayed-type","direct");
        return new CustomExchange("delayExchange","x-delayed-message",true,false,args);
    }
    //延时队列
    @Bean
    public Queue newQueue(){
        return new Queue("delayQueue",true);
    }
    //创建直连队列（提醒支付订单）
    @Bean
    public Queue goPayTipQueue(){
        return new Queue("goPayTipQueue",true);
    }
    //绑定
    @Bean
    public Binding binding(){
        return BindingBuilder.bind(newQueue()).to(newExchange()).with("orderDelayCancel").noargs();
    }
    //绑定
    @Bean
    public Binding binding4(){
        return BindingBuilder.bind(goPayTipQueue()).to(newExchange()).with("orderDelayTip").noargs();
    }
}
